function createMessage() {
  // 动态添加CSS样式
  if (!document.querySelector('#message-style')) {
    const style = document.createElement('style');
    style.id = 'message-style';
    style.textContent = `
      @keyframes messageEnter {
        0% { opacity: 0; transform: translateY(-20px); }
        100% { opacity: 1; transform: translateY(0); }
      }
      @keyframes messageLeave {
        0% { opacity: 1; transform: translateY(0); }
        100% { opacity: 0; transform: translateY(-20px); }
      }
      .message-fade-enter-active {
        animation: messageEnter 0.3s ease-out forwards;
      }
      .message-fade-leave-active {
        animation: messageLeave 0.3s ease-in forwards;
      }
      .message-box {
        position: fixed;
        top: 20px;
        right: 20px;
        padding: 12px 20px;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        z-index: 9999;
        display: flex;
        align-items: center;
        font-family: 'Inter', system-ui, sans-serif;
        font-size: 14px;
        font-weight: 500;
        transform-origin: top right;
        transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1.000);
      }
      .message-icon {
        margin-right: 12px;
        font-size: 16px;
      }
      .message-content {
        line-height: 1.5;
      }
      .message-success { background-color: #67c23a; color: #fff; }
      .message-error { background-color: #f56c6c; color: #fff; }
      .message-warning { background-color: #e6a23c; color: #fff; }
      .message-info { background-color: #409eff; color: #fff; }
      
      .message-box:hover {
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12), 0 3px 6px rgba(0, 0, 0, 0.08);
        transform: translateY(-2px);
      }
    `;
    document.head.appendChild(style);
  }

  // 基础消息函数
  const baseMessage = function(message, options = {}) {
    const config = {
      type: 'info',
      duration: 3000,
      position: 'top-right',
      offset: 20,
      ...options
    };

    // 创建DOM元素
    const messageEl = document.createElement('div');
    messageEl.className = `message-box message-fade-enter-active message-${config.type}`;

    // 设置图标
    const icons = {
      success: '<i class="fa fa-check-circle"></i>',
      error: '<i class="fa fa-times-circle"></i>',
      warning: '<i class="fa fa-exclamation-triangle"></i>',
      info: '<i class="fa fa-info-circle"></i>'
    };
    
    messageEl.innerHTML = `
      <span class="message-icon">${icons[config.type]}</span>
      <span class="message-content">${message}</span>
    `;

    // 设置位置
    const positions = config.position.split('-');
    const vertical = positions[0];
    const horizontal = positions[1];
    
    messageEl.style.cssText = `
      ${vertical}: ${config.offset}px;
      ${horizontal}: ${horizontal === 'center' ? '50%' : config.offset}px;
      ${horizontal === 'center' ? 'transform: translateX(-50%)' : ''};
    `;

    // 添加到页面
    document.body.appendChild(messageEl);

    // 自动移除
    setTimeout(() => {
      messageEl.classList.remove('message-fade-enter-active');
      messageEl.classList.add('message-fade-leave-active');
      setTimeout(() => {
        messageEl.remove();
      }, 1500);
    }, config.duration);
    
    // 点击关闭
    messageEl.addEventListener('click', () => {
      messageEl.classList.remove('message-fade-enter-active');
      messageEl.classList.add('message-fade-leave-active');
      setTimeout(() => {
        messageEl.remove();
      }, 1500);
    });
    
    return {
      close: () => {
        messageEl.classList.remove('message-fade-enter-active');
        messageEl.classList.add('message-fade-leave-active');
        setTimeout(() => {
          messageEl.remove();
        }, 1500);
      }
    };
  };

  // 返回消息对象，包含各种类型的消息方法
  return {
    success: (message, options = {}) => baseMessage(message, { type: 'success', ...options }),
    error: (message, options = {}) => baseMessage(message, { type: 'error', ...options }),
    warning: (message, options = {}) => baseMessage(message, { type: 'warning', ...options }),
    info: (message, options = {}) => baseMessage(message, { type: 'info', ...options }),
    // 保留原始调用方式
    default: baseMessage
  };
}

// 挂载到全局
window.message = createMessage();  